home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / egsexamples / other / poly.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  4.4 KB  |  193 lines

  1. /*
  2.  * FM
  3.  *
  4.  * A other kind of lines. Lines with a color range !
  5.  *
  6.  * (c) by VIONA-Development 1992/94
  7. */
  8.  
  9. #include <exec/types.h>
  10. #include <proto/exec.h>
  11. #include <egs/egsintui.h>
  12. #include <egs/proto/egsintui.h>
  13. #include <egs/egsgfx.h>
  14. #include <egs/proto/egsgfx.h>
  15. #include <egs/egs.h>
  16. #include <egs/proto/egs.h>
  17.  
  18. long RangeRand(int i );
  19.  
  20. /* die Zeiger auf unsere Libraries */
  21. struct Library *EGSIntuiBase;
  22. struct Library *EGSGfxBase;
  23. struct Library *EGSBase;
  24.  
  25.  
  26. /* Beschreibung einer Linie */
  27. struct Line
  28. {
  29.     int used;
  30.     long x1,y1;
  31.     long x2,y2;
  32. };
  33.  
  34.  
  35. /* Ausgabe eines regelmäßigen Sterns mit 4 Spitzen */
  36. void drawRect( EI_WindowPtr window, ULONG color,
  37.                     struct Line *line1,
  38.                     struct Line *line2 )
  39. {
  40.     EG_RastPortPtr rp = window->RPort;
  41.     long top  = window->BorderTop;
  42.     long left = window->BorderLeft;
  43.  
  44.     EG_SetAPen( rp, color );
  45.     EG_AreaMove( rp, left+line1->x1, top+line1->y1 );
  46.     EG_AreaDraw( rp, left+line2->x1, top+line2->y1 );
  47.     EG_AreaDraw( rp, left+line2->x2, top+line2->y2 );
  48.     EG_AreaDraw( rp, left+line1->x2, top+line1->y2 );
  49.     EG_AreaEnd( rp );
  50. }
  51.  
  52.  
  53. /* und hier passiert etwas */
  54. #define MAX_HISTORY     20
  55. #define SPEED           11
  56. #define COLORSPEED              6
  57.  
  58. void doThings( EI_WindowPtr window )
  59. {
  60.  
  61.     struct EG_AreaInfo areaInfo;
  62.     EG_Polygon areaBuffer[20];
  63.     struct Line history[MAX_HISTORY];
  64.     long x1,y1, x2,y2;
  65.     long dx1,dy1, dx2,dy2;
  66.     long dtime;
  67.     ULONG color;
  68.     ULONG dcolor;
  69.     int historyPos;
  70.     int i;
  71.  
  72.     /* TmpRas anlegen */
  73.     window->RPort->AreaInfo = EG_InitArea( &areaInfo, &areaBuffer[0],20 );
  74.     window->RPort->TmpRas = E_AllocBitMap( window->Width,
  75.                        window->Height,1,E_PIXELMAP,0,
  76.                        window->WScreen->EScreen->Map);
  77.  
  78.     /* History löschen */
  79.     for( i=0; i<MAX_HISTORY; i++ ) history[i].used = 0;
  80.  
  81.     /* Startwert bestimmen */
  82.     x1 = RangeRand( window->Width-1 );
  83.     y1 = RangeRand( window->Height-1 );
  84.     x2 = RangeRand( window->Width-1 );
  85.     y2 = RangeRand( window->Height-1 );
  86.     dtime = 1;
  87.     color = window->WinColors.Back;
  88.     if (color % 256 != 0)
  89.         {
  90.         color = E_GetRGB8( window->WScreen->EScreen,color);
  91.     }
  92.     /* Anmimationschleife */
  93.     historyPos = 1;
  94.     history[0].x1 = x1;
  95.     history[0].y1 = y1;
  96.     history[0].x2 = x2;
  97.     history[0].y2 = y2;
  98.     history[0].used = 1;
  99.     while( GetMsg( window->UserPort )==NULL )
  100.         {
  101.         /* das alte Stück entfernen */
  102.         if ( history[historyPos].used )
  103.             {
  104.             drawRect( window, window->WinColors.Back,
  105.                   &history[historyPos],
  106.                       &history[(historyPos+1) % MAX_HISTORY] );
  107.             }
  108.  
  109.         /* alles einen Schritt bewegen */
  110.         dtime--;
  111.              if ( dtime==0 )
  112.             {
  113.             dx1 = RangeRand( 2*SPEED ) - SPEED;
  114.             dy1 = RangeRand( 2*SPEED ) - SPEED;
  115.             dx2 = RangeRand( 2*SPEED ) - SPEED;
  116.             dy2 = RangeRand( 2*SPEED ) - SPEED;
  117.             dcolor = (((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 24) +
  118.              (((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 16) +
  119.              (((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 8);
  120.             dtime = RangeRand( 100 ) + 10;
  121.             }
  122.         x1 += dx1;
  123.         if ( x1<0 || x1>=window->Width )  { x1 -= dx1; dx1 = -dx1; }
  124.         y1 += dy1;
  125.         if ( y1<0 || y1>=window->Height ) { y1 -= dy1; dy1 = -dy1; }
  126.         x2 += dx2;
  127.         if ( x2<0 || x2>=window->Width )  { x2 -= dx2; dx2 = -dx2; }
  128.         y2 += dy2;
  129.         if ( y2<0 || y2>=window->Height ) { y2 -= dy2; dy2 = -dy2; }
  130.         color += dcolor;
  131.  
  132.         /* den neuen Wert speichern */
  133.         history[historyPos].x1 = x1;
  134.         history[historyPos].y1 = y1;
  135.         history[historyPos].x2 = x2;
  136.         history[historyPos].y2 = y2;
  137.         history[historyPos].used = 1;
  138.  
  139.         /* das neue Stück ausgeben */
  140.         drawRect( window, color,
  141.                   &history[(historyPos+MAX_HISTORY-1) % MAX_HISTORY],
  142.               &history[historyPos]);
  143.  
  144.         /* den zyklischen Puffer weiterführen */
  145.         historyPos = (historyPos + 1) % MAX_HISTORY;
  146.         }
  147. }
  148.  
  149.  
  150. /* das Hauptprogramm */
  151. void main( int argc, char *argv[] )
  152. {
  153.     static struct EI_NewWindow newWindow =
  154.         {
  155.         50,30, 400,300,
  156.         0,0, 0,0,
  157.         NULL,
  158.         EI_WINDOWCLOSE | EI_WINDOWBACK | EI_WINDOWDRAG,
  159.         NULL,
  160.         "Testfenster",
  161.         EI_SMART_REFRESH,
  162.         EI_iCLOSEWINDOW,
  163.         NULL,
  164.         {0,0,0,0,0,0,0},
  165.         NULL,
  166.         NULL
  167.         };
  168.     EI_WindowPtr window;
  169.  
  170.     /* die Libraries öffnen */
  171.     EGSIntuiBase = OpenLibrary( (UBYTE *)"egsintui.library", 0 );
  172.     if ( EGSIntuiBase )
  173.         {
  174.         EGSGfxBase = OpenLibrary( (UBYTE *)"egsgfx.library", 0 );
  175.         if ( EGSGfxBase )
  176.             {
  177.             EGSBase = OpenLibrary( (UBYTE *)"egs.library", 0 );
  178.             if ( EGSBase )
  179.                 {
  180.             window = EI_OpenWindow( &newWindow );
  181.             if ( window )
  182.                 {
  183.                 doThings( window );
  184.                 EI_CloseWindow( window );
  185.                 }
  186.                 CloseLibrary( EGSBase );
  187.                 }
  188.         CloseLibrary( EGSGfxBase );
  189.         }
  190.         CloseLibrary( EGSIntuiBase );
  191.         }
  192. }
  193.